package com.woniuxy.juc.cas;

import lombok.ToString;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 原子的字段更新
 * <P> Date: 2022/4/9:15:35
 * <P> Description:
 */
@sun.misc.Contended
public class AtomicFieldTest {

    public static void main(String[] args) {
        Student student = new Student();

        AtomicReferenceFieldUpdater updater =
                //TODO 参数1 哪个类的属性 属性的类型class 属性名字
                 AtomicReferenceFieldUpdater.newUpdater(Student.class,String.class,"name");

        updater.compareAndSet(student,null,"zs");
        System.out.println(student);



    }

    @ToString
    static class Student{
        volatile String name;

    }

}


